package com.csc.empmngt;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csc.empmngt.dao.EmployeeDAO;
import com.csc.empmngt.dto.EmployeeDTO;
import com.csc.empmngt.service.EmployeeService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class EmployeeController {
	
	private static final Logger logger = LoggerFactory.getLogger(EmployeeController.class);
	
	@Autowired
	protected EmployeeService employeeService;
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/api/emp", method = RequestMethod.GET)
	@ResponseBody
	public List<EmployeeDTO> findAll(Locale locale, Model model) {
		return employeeService.findAll();
	}
	
	
	@RequestMapping(value = "/api/emp/{id}", method = RequestMethod.GET)
	@ResponseBody
	public EmployeeDTO viewDetail(@PathVariable long id, Model model) {
		EmployeeDTO emp = employeeService.read(id);
		return emp;
	}
	
	
}
